<?php

class Core_Backend_Component_Design_View_Block_Template_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar){
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('design/block_template/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form){
    	$entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('template_form')
                ->addHiddenField('id', 'template[id]')
                ->addHiddenField('area_id', 'template[area_id]', $this->getSession()->get('managed_area_id'));
        $form->addTextboxField($this->__('share.label.name'), 'name', "template[name]", TRUE)
             	->addRequiredRule();
        $form->addSelectField($this->__('share.label.module'), 'module_id', 'template[module_id]', TRUE)
                ->setOption('--', '')
                ->bindData($this->getModules(), 'title', 'id')
                ->addRequiredRule();
        $form->addSelectField($this->__('design.label.web_theme'), 'website_theme', "template[website_theme]", TRUE)
                ->bindData($this->getThemes(), 'title', 'name')
             	->addRequiredRule();
        $form->addTextboxField($this->__('share.label.file_name'), 'file_name', "template[file_name]", TRUE)
             	->addRequiredRule();
        $form->addBooleanField($this->__('share.label.enable'), 'enabled', 'template[enabled]');
        $form->addTextareaField('', 'template_script', 'template_script', TRUE)
                ->setStyle('height', '500px')
                ->addRequiredRule();
        $form->createTab('base_option', $this->__('design.label.base_option'), array('field_name', 'field_module_id','field_website_theme','field_file_name', 'field_enabled'));
        $form->createTab('script_option', $this->__('design.label.script'), array('field_template_script'));
        if(!is_null($entity)){
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }
}